Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';



var pdValueStore = new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=PDValue',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) 
});






var fixedReportTypeStore = new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=FixedReportType',
		method:'GET'
		}), 
		reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
		]) ,
		autoLoad:true
});


var QueryCustType2Store = new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=QueryCustType2',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
});

var addCurrencyStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=Currency',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var currencyUnitStore = new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=CurrencyUnit',
		method:'GET'
		}), 
		reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
		]) ,
		autoLoad:true
	}); 

//查找客户表单
var form = new Ext.form.FormPanel({ 
renderTo:'search_panel',     
height : 200,
width:900,
id: 'findForm', 
title: '固定报表查询',
anchor:'80%', 
bodyStyle: 'margin:3px;text-align:left;', 
frame: true, 
labelWidth: 100, 
buttonAlign:'right',
items: 
[ {
	layout:"form",
	items:[{
		xtype: 'combo', 
		 id : "fixedReportType",
		 store :fixedReportTypeStore,
		fieldLabel: '固定报表类型',
		valueField : 'code',
		displayField : 'name',
		emptyText : '请选择固定报表类型...',
		allowBlank : false,
		typeAhead : true,
		width: 200,
		mode:'remote',  
		hiddenName:'fixedReportType',
		editable: false,
		triggerAction : 'all',
		selectOnFocus : true 
	}]
},{
	layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'combo', 
        	   id : "queryCustType2",
        	   store :QueryCustType2Store,
        	  fieldLabel: '客户类型',
        	  valueField : 'code',
        	  displayField : 'name',
        	  emptyText : '请选择客户类型...',
        	  allowBlank : true,
        	  typeAhead : true,
        	  width: 200,
        	  mode:'remote',  
        	  hiddenName:'queryCustType2',
        	  editable: false,
        	  triggerAction : 'all',
        	  selectOnFocus : true   
}]},{ columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'combo',
				id: 'orgCode',
				//name: 'exposureType', 
				fieldLabel: '经办机构', 
				store:new Ext.data.SimpleStore({fields:['id', 'text'],data:[[]]}), 
				displayField: 'text',
				valueField: 'id',
				hiddenName: 'orgCode',
	            editable:false, 
	            mode: 'local', 
	            triggerAction:'all', 
	            frame:true,
	            border:true,
	            width:200,
	            tpl: '<div id="treePanel" style="height:180px;width:240px;"></div>', //html代码      
	            emptyText:'请选择经办机构...',
	            resizable:true
}]} 
]},{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	    layout : "form",
	    items : [{
	    xtype: 'datefield',
			id: 'date', 
			name: 'date', 
			fieldLabel: '报表日期',
			allowBlank: true,
			editable:false,  
			format : 'Y-m' ,
			width: 200
	}
	]},{ columnWidth : .5, // 该列有整行中所占百分比
	       layout : "form",
	       items : [{
			xtype: 'textfield', 
			id: 'userId',
			name: 'userId', 
			fieldLabel: '经办人编号',  
			allowBlank: true, 
			width:200
			}]} 
	]},
//	{
//	layout:"column",
//	items:[{
//		columnWidth : .5, // 该列有整行中所占百分比
//	    layout : "form",
//	    items : [{
//	    xtype: 'datefield',
//			id: 'startDate', 
//			name: 'startDate', 
//			fieldLabel: '起始日期',
//			allowBlank: true,
//			editable:false,  
//			format : 'Y-m-d' ,
//			width: 200
//	}
//	]},{
//		columnWidth : .5, // 该列有整行中所占百分比
//	    layout : "form",
//	    items : [{
//	    xtype: 'datefield',
//			id: 'endDate', 
//			name: 'endDate', 
//			fieldLabel: '结束日期',
//			allowBlank: true,
//			editable:false,  
//			format : 'Y-m-d' ,
//			width: 200
//	}
//	]} 
//]},
{
	layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
               xtype: 'combo', 
    			id : "currency",
                 store :addCurrencyStore,
               fieldLabel: '币种',
                 valueField : 'code',
                 displayField : 'name',
                 emptyText : '请选择币种...',
                 editable: false,
                 typeAhead : true,
                 width: 200,
                 mode:'remote',  
                 triggerAction : 'all',
                 selectOnFocus : true,
                 hiddenName:'currency'
   }]},{ columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'combo', 
        	   id : "currencyUnit",
        	   store :currencyUnitStore,
        	  fieldLabel: '金额单位',
        	  valueField : 'code',
        	  displayField : 'name',
        	  emptyText : '请选择金额单位（默认万元）...',
        	  allowBlank : true,
        	  typeAhead : true,
        	  width: 200,
        	  mode:'remote',  
        	  hiddenName:'currencyUnit',
        	  editable: false,
        	  triggerAction : 'all',
        	  selectOnFocus : true   
}]} 
]}
],
buttons:[{text:"查询", handler: findCustomer},
{text:"重置", handler: function(){ Ext.getCmp('findForm').form.reset();}}]
});

var tree = new Ext.tree.TreePanel
({ 
    animate:true,
    titleCollapse:true,
    root:root,
    singleExpand:false,
    iconCls:"icon-tree",
    autoLoad:false,
    allowDomMove:true,
    frame:true,
    collapsible:false,
    collapsed:false,
    collapseFirst:true,
    border:false,
    listeners:{ 
    	render:function(tree){ 
    		tree.el.on('click',function(e){ 
			e.stopPropagation(); }) ;
		} 
	} 
});

var loader=new Ext.tree.TreeLoader({dataUrl:'system/showOrgTree.do'});

var root=new Ext.tree.AsyncTreeNode
({
 id:"0", 
 leaf:false,
 loader: loader,
 text:"清远农商行总行",
 expandable:true,
 expanded:true 
});         

tree.setRootNode(root);

var comboTree =  Ext.getCmp('orgCode');      
var orgCode = "";
comboTree.on('expand',function(){tree.render('treePanel');});

var tree_click = function(node,e)
{
	 e.stopEvent();   //非叶子节点则不触发
     comboTree.setValue(node.id);  //设置option值
     comboTree.setRawValue(node.text);
     //comboTree.hiddenField.value = node.id;  
 	comboTree.collapse();   //隐藏option列表
// 	alert(comboTree.value);
// 	alert(comboTree.getValue());
// 	alert(comboTree.getRawValue());
// 	alert(comboTree.value);
 	orgCode = comboTree.value;
};
tree.on("click",tree_click);  

//表单验证-都为空
Ext.apply(Ext.form.VTypes,   
{
 allNull: function(val, field){
 if(field.allNull){
 	var custTypeId = field.allNull.custType;
 	this.custTypeField = Ext.getCmp(custTypeId);
 	var custNameId = field.allNull.custName;
 	this.custNameField = Ext.getCmp(custNameId);
 	var orgId = field.allNull.organizationID;
 	this.orgIdField = Ext.getCmp(orgId);
 	var blId = field.allNull.busiLicenseID;
 	this.blIdField = Ext.getCmp(blId);
 	
 	var custTypeValue = this.custTypeField.getValue();
 	var custNameValue = this.custNameField.getValue();
 	var orgIdValue = this.orgIdField.getValue();
 	var blIdValue = this.blIdField.getValue();
 } 
 if(custTypeValue==null&&custNameValue==null&&orgIdValue==null&&blIdValue==null){
 	Ext.MessageBox.show({
                     title: '提示',
                     msg: '请输入至少一项查询条件！',
                     buttons: Ext.Msg.OK
                });
 	return false;
 }
 else{
 	return true;
 }
 }
});
//查询客户 
function findCustomer() { 
	var findForm = Ext.getCmp("findForm");
	//alert("查询");
	
	if(findForm.form.isValid()){
		var form = findForm.getForm().getEl().dom;
		form.action = 'RiskReport/getFixedReport.do';
		form.method='post';
		form.submit();
}
} 

});